﻿using System;
using System.Collections.Generic;
using System.Text;

using MapCenterSystem.DataInfo;
using System.Data.SqlClient;
using MapCenterSystem.Configuration;
using System.Data;
using MapCenterSystem.DefineType;
namespace MapCenterSystem.DataAccess
{
    public class MyLocationDAO 
    {
        public MyLocation GetNameLocationStressNearMyLocation(double latatude, double longtatude)
        {
            using (SqlConnection sqlConnect = new SqlConnection(GlobalConfig.ConnectionString))
            {
                SqlCommand command = new SqlCommand();
                command.CommandText = "sp_Address_FindExactAddressByCoordinate";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = sqlConnect;
                //command.CommandTimeout = GlobalConfig.TimeOut;
                command.Parameters.AddWithValue("@xLocation", latatude);
                command.Parameters.AddWithValue("@yLocation", longtatude);
                try
                {
                    sqlConnect.Open();
                }
                catch
                {
                    throw new Exception("Can not connect to database. Please check connect");
                }
                SqlDataReader reader = command.ExecuteReader();
                //chỗ này phải trả về cái list adhoc đi hehe
                String result = String.Empty;
                MyLocation myLocation = new MyLocation();
                while (reader.Read())
                {
                    myLocation.Id = Convert.ToInt32(reader["ID"]);
                    myLocation.Number = Convert.ToString(reader["Number"]);
                    myLocation.Area = Convert.ToString(reader["Area"]); ;
                    myLocation.XLocation = Convert.ToDouble(reader["xLocation"]);
                    myLocation.YLocation = Convert.ToDouble(reader["yLocation"]);
                }
                return myLocation;
            }
        }
    }
}

